﻿using UnityEngine;
using System.Collections;

public class PlayerShipShots_Script : MonoBehaviour 
{
	//Public Var
	public float speed; //Speed of the velocity
	public GameObject LaserGreenHit;
	public GameObject Aim;

	float distanceFromCamera = 1.0f;

	// Use this for initialization
	void Start ()
	{
		var pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distanceFromCamera);
		pos = Camera.main.ScreenToWorldPoint(pos);

		Vector3 direction =  Aim.transform.position/*pos*/ - transform.position;
		direction.z = 0.0f;
		direction.Normalize();

		transform.localRotation = Quaternion.LookRotation(Vector3.forward, direction);
		GetComponent<Rigidbody2D>().velocity = direction * speed;
	}

	public void Die()
	{
		Instantiate (LaserGreenHit, transform.position, transform.rotation); 		//Instantiate LaserGreenHit 
		Destroy (gameObject);
	}
}
